package com.homwee.factory;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.mediatek.twoworlds.tv.MtkTvUtil;

public class ShowFactoryTipsService extends Service {
        private String Tips;

	@Override
	public IBinder onBind(Intent arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int onStartCommand(Intent intent, int flags, int startId) {
		// TODO Auto-generated method stub
		mWindowManager = (WindowManager) getApplication().getSystemService(
				Context.WINDOW_SERVICE);
		mInflater = LayoutInflater.from(getApplication());
                Tips = intent.getStringExtra("Tips");
		MtkTvUtil.IRRemoteControl(1);
		createMainView();
		mWindowManager.addView(mRootLayout, wmParams_main);
		return START_NOT_STICKY;
	}

	static WindowManager mWindowManager;
	LayoutInflater mInflater;
	LayoutParams wmParams_main;
	private LinearLayout mRootLayout;

	@Override
	public void onCreate() {
		// TODO Auto-generated method stub
		super.onCreate();
	}

	private void createMainView() {
		wmParams_main = new LayoutParams();
		wmParams_main.type = LayoutParams.TYPE_PHONE;
		wmParams_main.gravity = Gravity.CENTER | Gravity.TOP;
		wmParams_main.x = 0;
		wmParams_main.y = 0;
		wmParams_main.flags = LayoutParams.FLAG_ALT_FOCUSABLE_IM
				| LayoutParams.FLAG_NOT_FOCUSABLE;
		wmParams_main.width = LayoutParams.MATCH_PARENT;
		wmParams_main.height = LayoutParams.MATCH_PARENT;
		mRootLayout = (LinearLayout) mInflater.inflate(
				R.layout.factory_tips_view, null);
                TextView tv = (TextView)mRootLayout.findViewById(R.id.tv_show_tips); 
                if(Tips != null){
                    tv.setText(Tips);
                    tv.setTextColor(android.graphics.Color.BLUE);
                }
                
	}

	@Override
	public void onDestroy() {
		// TODO Auto-generated method stub
		stopSelf();
		Log.d("zcj", "stop");
		mWindowManager.removeView(mRootLayout);
		android.os.Process.killProcess(android.os.Process.myPid());
		super.onDestroy();
	}

}
